package erfen;

import java.util.ArrayList;
import java.util.List;

public class Solution_75 {
    public boolean searchMatrix(int[][] matrix, int target) {
        List<Integer> list = new ArrayList<>();
        for (int[] ints : matrix) {
            for (int i : ints) {
                list.add(i);
            }
        }
        int[] arr=new int[list.size()];
        for (int i = 0; i < list.size(); i++) {
            arr[i]=list.get(i);
        }
        int index = binarySearch(arr, target);
        return index < list.size() && arr[index] == target;
    }

    public int binarySearch(int[] nums, int target) {
        int left=0,right=nums.length-1;
        while (left<=right){
            int mid=(left+right)>>>1;
            if(nums[mid]>=target)
                right=mid-1;
            else left=mid+1;
        }
        return left;
    }
}
